package com.wiloon.java8x.thread;

/**
 * Created by Roy on 2015/11/13;
 */

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestCachedThread {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        for (int index = 0; index < 10; index++) {
            Runnable run = () -> {
                long time = (long) (Math.random() * 1000);
                System.out.println("start: "+time);

                System.out.println("sleep:" + time + " ss ");
                try {
                    Thread.sleep(time);
                } catch (Exception e) {

                }
                System.out.println("complete: "+time);
            };
            exec.execute(run);
        }
        exec.shutdown();
    }
}